package com.flyoil.petromp.adapter.adapter_home;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.flyoil.petromp.R;
import com.flyoil.petromp.base.MyBaseAdapter;
import com.flyoil.petromp.entity.entity_home.HomeMenuEntity;

/**
 * Created by songzhiiyn on 2017/10/10.
 * 主页功能按钮列表的适配器
 */

public class ItemHomeMenuAdapter extends MyBaseAdapter<HomeMenuEntity> {

    public ItemHomeMenuAdapter(Context context) {
        super(context);
    }

    @Override
    public View setView(int position, View convertView, ViewGroup parent) {
        Hoderview hoderview;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_home_menu_adapter, null);
            hoderview = new Hoderview(convertView);
            convertView.setTag(hoderview);
        } else {
            hoderview = (Hoderview) convertView.getTag();
        }
        HomeMenuEntity entity = (HomeMenuEntity) getItem(position);
        hoderview.tv_name.setText(entity.getName());
        hoderview.img_icon.setImageResource(entity.getUrl());
        return convertView;
    }

    private class Hoderview {
        private TextView tv_name;
        private ImageView img_icon;

        public Hoderview(View view) {
            this.tv_name = view.findViewById(R.id.tv_item_home_menu_adapter_name);
            this.img_icon = view.findViewById(R.id.img_item_home_menu_adapter_icon);
        }
    }
}
